/**
* @file 滚动刷新组件
* @author renzhiqiang
* @date 2017/1/22
*/
<template>
  <div class="mui-content">
    <div v-if="listData.length==0" class='list_is_null'></div>
    <div v-show="listData.length>0">
      <div v-if="configure.showCount" class="show_total">{{nowTotal}}/{{totalSize}}</div>
      <div :id="configure.id" class="mui-scroll-wrapper chance-list-wrapper" :style="{ top: top + 'px', fontSize: 32 + 'px' }">
        <div class="mui-scroll">
          <slot></slot>
        </div>
    </div>
    </div>
  </div>
</template>
<script>
  export default{
    props: {
      pageno:{ // 第几页 初始化默认第一条
        type: Number,
        default: 0
      },
      pagesize: {  // 一页多少条,默认10
        type: Number,
        default: 10
      },
      configure: {}, // 数据源配置
      scroll: {},
      downContent: String,
      ownOverContent: String,
      downRefreshContent: String,
      upRefreshContent: String,
      nomoreContent: String,
      isDisablePulluptoRefresh: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      // 获取数据数组列表
      listData: function () {
        console.info('111');
        return this.configure.dataSource.dataSource.data ? this.configure.dataSource.dataSource.data : [];
      },
      // 计算数据总数
      totalSize: function () {
        return this.configure.dataSource.dataSource.data ? this.configure.dataSource.dataSource.totalSize : 0;
      },
      // 计算当前页数量
      nowTotal: function () {
        return this.configure.dataSource.dataSource.data ? this.configure.dataSource.dataSource.data.length : 0;
      },
      // 计算列表距离顶部高度
      top: function () {
        return this.configure.showCount ? this.configure.top : this.configure.top-10;
      }
    },
    events: {
      'refresh': function (item) {
//        mui('#'+configure.id).pullRefresh();
      }
    },
    methods: {
      pulldownRefresh: function () {
        scroll.pullDirection = 'down';
        this.$dispatch('pulldown', this.scroll);
      },
      pullupRefresh: function () {
        scroll.pullDirection = 'up';
        this.$dispatch('pullup', this.scroll);
      },
      disablePullupToRefresh: function () {
        mui('#'+configure.id).pullRefresh().disablePullupToRefresh();
      },
      enablePullupToRefresh: function () {
        mui('#'+configure.id).pullRefresh().enablePullupToRefresh();
      }
    },
    ready: function () {
      this.scroll = mui('#'+this.configure.id).pullRefresh({
        container: '#'+this.configure.id,
        down: {
          contentdown: this.downContent,
          contentover: this.ownOverContent,
          contentrefresh: this.downRefreshContent,
          callback: this.pulldownRefresh
        },
        up: {
          contentrefresh: this.upRefreshContent,
          contentnomore: this.nomoreContent,
          callback: this.pullupRefresh
        }
      });
      this.$dispatch('pullRefreshReady', this.scroll);
      if (this.isdisablePullupToRefresh) {
        this.disablePullupToRefresh();
      }
      this.$watch('isDisablePulluptoRefresh', function (newVal) {
        if (newVal) {
          this.enablePullupToRefresh();
        }
        else {
          this.disablePullupToRefresh();
        }
      });
    }
  }
</script>
